package com.yc.game.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.cms.dao.MoneyMapper;
import com.yc.game.cms.pojo.Money;
import com.yc.game.cms.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MoneyServiceImpl implements MoneyService {
    @Autowired
    private MoneyMapper moneyMapper;
    @Override
    public PageInfo<Money> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Money> monies = moneyMapper.getAll();
        PageInfo<Money> pageInfo = new PageInfo<>(monies);
        return pageInfo;

    }

    /**
     * 更新金额
     * @param money
     * @return
     */
    @Override
    public int update(Money money) {
        Money newMoney = new Money();
        newMoney.setId(money.getId());
        newMoney.setMoney(money.getMoney());
        newMoney.setStatus(money.getStatus());
        return moneyMapper.updateByPrimaryKeySelective(newMoney);
    }

    /**
     * 删除保证金用户
     * @param moneyId
     * @return
     */
    @Override
    public int deleteById(Integer moneyId) {
        return moneyMapper.deleteByPrimaryKey(moneyId);
    }
}
